package tree;

/**
 * @author way
 * @create 2025-02-13 12:54
 */
public class _530_getMinimumDifference {
    TreeNode pre;
    int res = Integer.MAX_VALUE;

    public int getMinimumDifference(TreeNode root) {
        if (root == null) return 0;

        traversal(root);
        return res;
    }

    private void traversal(TreeNode root) {
        if (root == null) return;
        traversal(root.left);

        if (pre!=null){
            res = Math.min(res,root.val-pre.val);
        }

        pre = root;
        traversal(root.right);
    }
}
